<template>
  <div class="ai-prediction">
    <div class="header">
      <h2 style="white-space: nowrap; margin-right: 20px;">AI预测</h2>
      <el-select v-model="predictionType" placeholder="选择预测类型" size="small" style="min-width: 120px;">
        <el-option label="未来7天" value="7days" />
        <el-option label="未来30天" value="30days" />
        <el-option label="未来90天" value="90days" />
      </el-select>
    </div>

    <div class="prediction-overview">
      <el-row :gutter="20" style="margin-bottom: 20px;">
        <el-col :span="24">
          <el-card shadow="hover">
            <template #header>
              <div class="card-header">
                <span>能耗预测</span>
                <el-tag size="small" type="success">95.8%</el-tag>
              </div>
            </template>
            <div class="card-content">
              <div class="accuracy-chart">
                <prediction-chart height="200px" />
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-card shadow="hover">
            <template #header>
              <div class="card-header">
                <span>异常预测</span>
              </div>
            </template>
            <div class="card-content">
              <div class="alert-list">
                <el-card v-for="alert in alerts" :key="alert.id" shadow="hover" class="alert-card">
                  <template #header>
                    <div class="card-header">
                      <span>{{ alert.title }}</span>
                      <el-tag :type="alert.severity === 'high' ? 'danger' : 'warning'" size="small">
                        {{ alert.severity === 'high' ? '严重' : '警告' }}
                      </el-tag>
                    </div>
                  </template>
                  <div class="card-content">
                    <p>{{ alert.description }}</p>
                    <p class="alert-time">{{ alert.time }}</p>
                  </div>
                </el-card>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <div class="prediction-details">
      <el-card shadow="hover">
        <template #header>
          <div class="card-header">
            <span>预测详情</span>
            <el-button type="primary" size="small">导出报告</el-button>
          </div>
        </template>
        <el-table :data="predictionList" style="width: 100%">
          <el-table-column prop="time" label="时间" />
          <el-table-column prop="actual" label="实际值" />
          <el-table-column prop="predicted" label="预测值" />
          <el-table-column prop="accuracy" label="准确率">
            <template #default="{ row }">
              <el-progress
                :percentage="row.accuracy"
                :status="row.accuracy >= 90 ? 'success' : 'warning'"
              />
            </template>
          </el-table-column>
          <el-table-column prop="status" label="状态">
            <template #default="{ row }">
              <el-tag :type="row.status === '正常' ? 'success' : 'warning'">
                {{ row.status }}
              </el-tag>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>

    <div class="model-info">
      <el-card shadow="hover">
        <template #header>
          <div class="card-header">
            <span>模型信息</span>
          </div>
        </template>
        <el-descriptions :column="2" border>
          <el-descriptions-item label="模型名称">LSTM</el-descriptions-item>
          <el-descriptions-item label="训练数据量">10,000条</el-descriptions-item>
          <el-descriptions-item label="特征数量">15个</el-descriptions-item>
          <el-descriptions-item label="最后更新时间">2024-03-15</el-descriptions-item>
          <el-descriptions-item label="平均准确率">95.8%</el-descriptions-item>
          <el-descriptions-item label="模型版本">v2.1.0</el-descriptions-item>
        </el-descriptions>
      </el-card>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import PredictionChart from '@/components/charts/PredictionChart.vue'

const predictionType = ref('7days')
const timeRange = ref('day')

const predictionList = ref([
  {
    time: '2024-03-15 10:00',
    actual: '2.5 kW',
    predicted: '2.4 kW',
    accuracy: 96,
    status: '正常'
  },
  {
    time: '2024-03-15 11:00',
    actual: '2.8 kW',
    predicted: '2.7 kW',
    accuracy: 96.4,
    status: '正常'
  },
  {
    time: '2024-03-15 12:00',
    actual: '3.2 kW',
    predicted: '3.0 kW',
    accuracy: 93.8,
    status: '正常'
  },
  {
    time: '2024-03-15 13:00',
    actual: '2.9 kW',
    predicted: '3.2 kW',
    accuracy: 89.7,
    status: '注意'
  }
])

const alerts = ref([
  {
    id: 1,
    title: '火灾风险',
    description: '实验室A存在火灾风险，请检查设备运行状态。',
    severity: 'high',
    time: '2024-03-15 14:30'
  },
  {
    id: 2,
    title: '中毒风险',
    description: '实验设备A可能存在有毒气体泄漏，请及时处理。',
    severity: 'warning',
    time: '2024-03-15 10:15'
  }
])
</script>

<style scoped>
.ai-prediction {
  padding: 20px;
  height: 100%;
  overflow-y: auto;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header h2 {
  margin: 0;
  font-size: 24px;
  color: #333;
}

.prediction-overview {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-content {
  padding: 10px 0;
}

.accuracy-chart,
.trend-chart {
  height: 200px;
}

.prediction-details {
  margin-bottom: 20px;
}

.model-info {
  margin-bottom: 20px;
}

.alert-card {
  margin-bottom: 20px;
}

.alert-time {
  color: #999;
  font-size: 12px;
  margin-top: 10px;
}
</style> 